package com.mic.core.model.page;

import java.io.Serializable;


public  class PageContext implements Serializable {
	

	public  Integer pageCount = 20;


	private Integer currentPage = 0;


	private Integer totalCount = 0;


	private Integer totalPage = 0;
	
	private Integer start = 0;



	public void refresh(Integer totalCount){
		

		this.totalCount = totalCount;
		

		if (totalCount == 0)
			this.totalPage = 0;
		else
			this.totalPage = (totalCount - 1) / pageCount + 1;
		

		if (currentPage == null)
			currentPage = 1;
		if (currentPage < 1 || currentPage > totalPage)
			currentPage = 1;
		
		start = (currentPage-1)*pageCount;

	}


	// getters and setters
	public Integer getPageCount() {
		return pageCount;
	}

	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}
	

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}
	
	public Integer getStart() {
		return start;
	}

	public void setStart(Integer start) {
		this.start = start;
	}

	@Override
	public String toString() {
		return "PageContext [pageCount=" + pageCount + ", currentPage="
				+ currentPage + ", totalCount=" + totalCount + ", totalPage="
				+ totalPage + ", start=" + start + "]";
	}


}
